using System;
using System.Collections.Generic;
using System.Text;
using Lizk.DShowPlayer;
using Lizk.SimpleHUD;
using XNAHUDEngine;
using Microsoft.Xna.Framework.Graphics;

namespace SharpMedia.MDX
{
    public abstract class XNAVideo
    {
        public static object videoLoadLock = new object();
        public Allocator2 allocator;
        public bool restart;
        public bool resumeAfterRestart;
        public TimeSpan restartPosition;
        public abstract Player Player {get; }
        public HUDVideo2 video;
        public abstract void Unload();
        public bool Disposed = false;
        protected XNAForm form;

        public abstract void Restart();

        public XNAVideo(XNAForm form, HUDVideo2 video)
        {
            this.form = form;
            this.video = video;

        }

        public virtual void Update()
        {
            while (video.Updater.PendingCommands.Count > 0)
            {
                KeyValuePair<HUDVideo2.VideoCommands, object[]> kvp = video.Updater.PendingCommands.Dequeue();
                HandleVideoCommand(kvp.Key, kvp.Value);
            }
        }
        public abstract void HandleVideoCommand(HUDVideo2.VideoCommands command, object[] parameters);

        private Texture2D texture;

        public Texture2D Texture
        {
            get { return allocator == null ? null : texture; }
        }


        public void UpdateTexture()
        {
            if (allocator != null)
                texture = allocator.GetImage();
            else
                texture = null;
        }


    }
}
